<?php

namespace App\Http\Controllers\Admin;

use App\Models\Brand;

class BrandController extends BaseController
{
    public function __construct(Brand $brand)
    {
        parent::__construct();
        $this->brand = $brand;
    }

    /**
     * 首页
     * @return \Illuminate\Http\JsonResponse
     * 品牌管理列表
     */
    public function getIndex()
    {
        $rows = $this->brand->getBrandList(request());
        $flag = 'brand';
        return view('admin.brand.index',compact('rows','flag'));
    }

    /**
     *
     * @return \Illuminate\Http\JsonResponse
     * 品牌管理详情->基本信息
     *
     */
    public function getBrandInfo()
    {

        $res = $this->brand->getBrandInfo(request());
        $flag = 'brand';
        return view('admin.brand.details',compact('res','flag'));
    }

    //基本信息修改
    public function postEditInfo(){
        $res = $this->brand->editBrandInfo(request());
        if($res['status']==0){
            return redirect()->back()->with('message', $res['msg'])->withInput();
        }else{
            return redirect()->back()->with('message', $res['msg'])->withInput();
        }
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * 品牌管理详情->代理成员
     */
    public function getBrandAgentList()
    {
        $res = $this->brand->getBrandAgentList(request());
        $flag = 'brand';
        return view('admin.brand.agent_list',compact('res','flag'));
    }

    //添加品牌表单
    public function getAdd()
    {
        //$res = $this->brand->addBrand(request());
        //return ajax_return($res);
        $flag = 'brand';
        return view('admin.brand.agent_add',compact('flag'));
    }

    //添加品牌表单提交
    public function postAdd()
    {
        //dd($_POST);
        $res = $this->brand->addBrand(request());
        return ajax_return($res);
    }

    //审核管理控制器
    public function getApply()
    {
        $res = $this->brand->getApplyList(request());
        $flag = 'index';
        //dd($res);
        return view('admin.index.verify',compact('res','flag'));
    }

    public function postVerify()
    {
        $res = $this->brand->verify(request());
        return ajax_return($res);
    }

    //ajax删除品牌商
    public function getDel()
    {
        $res = $this->brand->deleteOneBrand(request());
        return ajax_return($res);

    }


    public function getImageSoucer()
    {
        $res = $this->brand->getImageData(request());
        //$file = 'upload/agent/'.session('agentId').'.png';
        //dd($res);
        $data['proxy'] = $res['proxy'];

        $flag = 'shu';
        return view('admin.index.agent_img',compact('data','flag'));
    }
    
    public function getModifyPwd()
    {
        $flag = 'brand';
        return view('admin.brand.modifyPwd',compact('flag'));
    }

    public function postModifyPwd()
    {
        $res = $this->brand->modifyPwd(request());
        return redirect()->back()->with('message', $res)->withInput();
    }

}

